package com.foreknow.demo13;

import java.io.*;

public class TestEmployee {
    public static void main(String[] args) {
        //        try {
        //            //定义对象输出流
        //            FileOutputStream fos = new FileOutputStream("abc.ser");
        //            ObjectOutputStream oos = new ObjectOutputStream(fos);
        //            oos.writeObject(new Employee("张三",23,"market"));
        //            oos.writeObject(new Employee("李四",22,"program"));
        //            oos.close();
        //        } catch (IOException e) {
        //            e.printStackTrace();
        //        }

        try {
            //反序列化操作（相当于将字节码文件转换为对象）
            FileInputStream fis = new FileInputStream("abc.ser");
            ObjectInputStream ois = new ObjectInputStream(fis);
            //读对象
            Employee emp1 = (Employee) ois.readObject();
            Employee emp2 = (Employee) ois.readObject();
            System.out.println(emp1.getName());
            System.out.println(emp2.getName());
            //关闭资源
            ois.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
